package com.aaa.ssm.controller;

import com.aaa.ssm.pojo.dto.EmpDTO;
import com.aaa.ssm.pojo.dto.StudentDTO;
import com.aaa.ssm.pojo.dto.StudentVO;
import com.aaa.ssm.pojo.vo.StudentQuery;
import com.aaa.ssm.result.AjaxResult;
import com.aaa.ssm.service.StudentService;
import com.aaa.ssm.service.impl.EmpServiceImpl;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;

@RestController
@RequestMapping("stu")
public class StudentController {
   @Autowired
   private StudentService studentService;

    @RequestMapping("query")
    public AjaxResult query(StudentQuery query){
        try {
            Map<String,Object> map=studentService.listAllStudent(query);
            return AjaxResult.success(map);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }

    };
    @RequestMapping("add")

    public AjaxResult addStudent(StudentDTO studentDTO){
        try {
            int student = studentService.addStudent(studentDTO);
            return AjaxResult.success(student);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
    };
    @RequestMapping("update")
    public AjaxResult update(StudentVO s){
        try {
            System.out.println("jkjk");
            Integer i = studentService.updateStuByteID(s);
            if (i>0){
                return AjaxResult.success();
            }else {
                return AjaxResult.error();
            }
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
    };
    @RequestMapping("get/{id}")
    public AjaxResult get(@PathVariable("id") Integer id){
        try {
            StudentDTO stuByteID = studentService.getStuByteID(id);
            return AjaxResult.success(stuByteID);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
    };
    @RequestMapping("delete/{id}")
    public AjaxResult deleteStudent(@PathVariable("id") Integer id){
        try {
            Integer result=  studentService.deleteStudent(id);
            if (result>0){
                return AjaxResult.success();
            }else {
                return AjaxResult.error();
            }

        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }

    };
}
